package action.admin.mclass;

import dao.MngClass;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class editClass extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            String action = request.getParameter("action");
            if (action.equals("delete")) {
                String class_id = request.getParameter("class_id");
                MngClass mngClass = new MngClass();
                String msg = "";
                String error = "";
                if (mngClass.deleteClass(class_id)) {
                    msg = "Delete successful !";
                } else {
                    error = "Delete fail !";
                }
                request.setAttribute("msg", msg);
                request.setAttribute("error", error);
                RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=class");
                rd.forward(request, response);
            } else if (action.equals("update")) {
                String class_id = request.getParameter("class_id");
                String acc_id = request.getParameter("acc_id");
                String class_name = request.getParameter("class_name");
                String start_date = request.getParameter("start_date");
                String finish_date = request.getParameter("finish_date");
                String description = request.getParameter("description");
                request.setAttribute("acc_id", acc_id);
                request.setAttribute("class_id", class_id);
                request.setAttribute("class_name", class_name);
                request.setAttribute("finish_date", finish_date);
                request.setAttribute("start_date", start_date);
                request.setAttribute("description", description);
                RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=update_class");
                rd.forward(request, response);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
